package com.example.spzx.controller;

import com.example.spzx.Log;
import com.example.spzx.Mapper.SysRoleMapper;
import com.example.spzx.Service.SysRoleService;
import com.example.spzx.model.entity.system.SysRole;
import com.example.spzx.model.vo.common.Result;
import com.example.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/system/sysRole")
public class SysRoleController {
@Resource
private SysRoleService sysRoleService;
@Resource
private SysRoleMapper sysRoleMapper;
    @GetMapping("/findByPage/{pageNum}/{pageSize}")
    public Result<SysRole> list(@RequestParam("roleName") String roleName, @PathVariable("pageNum") Integer pageNum, @PathVariable("pageSize") Integer pageSize){

        PageInfo<SysRole> pageResult=sysRoleService.selectlist(roleName,pageNum,pageSize);
        return Result.build(pageResult, ResultCodeEnum.SUCCESS);
    }
    @Log(title = "角色添加",businessType = 0)
    @PostMapping("/saveSysRole")
    public Result<SysRole> add(@RequestBody SysRole sysRole){
        sysRoleService.add(sysRole);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    @PutMapping("/updateSysRole")
    public Result<SysRole> update(@RequestBody SysRole sysRole){
        sysRoleService.update(sysRole);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    @GetMapping("/delete")
    public Result<SysRole> delete(@RequestParam("id") Integer id){
        sysRoleService.delete(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    @GetMapping("/all")
    public Result<SysRole> all(){
        List<SysRole> list=sysRoleService.selectall();
        return Result.build(list,ResultCodeEnum.SUCCESS);
    }

}
